package com.right.health.app.ui.registered;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.magic.basic.adapter.FragmentViewPagerAdapter;
import com.right.health.app.R;
import com.right.health.app.base.BasePresenterActivity;
import com.right.health.app.bean.DateOffsetInfo;
import com.right.health.app.bean.DepartmentInfo;
import com.right.health.app.constants.BroadCastKey;
import com.right.health.app.ui.registered.fragment.DoctorFragment;
import com.right.health.app.ui.registered.presenter.ChooseDoctorPresenter;
import com.right.health.app.widget.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.List;

/*
 * Created by hopeliao on 2019-09-26
 * 选择医生
 *
 */
public class ChooseDoctorActivity extends BasePresenterActivity<ChooseDoctorPresenter, String> {

    @Override
    public void onCreate(Bundle bundle, String s) {
        setContentView(R.layout.choose_doctor);
    }

    @Override
    public void findView() {
        Bundle bundle =getIntent().getExtras();
        if(bundle != null && bundle.containsKey(BroadCastKey.DATA)) {
            DepartmentInfo mDepartmentInfo = bundle.getParcelable(BroadCastKey.DATA);
            String code = bundle.getString(ChooseDepartmentActivity.EXTRA_CODE);

            ViewPager mTabViewPager = (ViewPager) findViewById(R.id.viewpager);
            mTabViewPager.setOffscreenPageLimit(3);

            PagerSlidingTabStrip slidingTabs = (PagerSlidingTabStrip) findViewById(R.id.pager_tab_strip);

            ArrayList<Fragment> mFragmentList = new ArrayList<>();
            List<DateOffsetInfo> titles = getPersenter().getTitles();
            String[] tempTitles = new String[titles.size()];

            for (int i = 0; i < titles.size(); i++) {
                DateOffsetInfo info = titles.get(i);
                mFragmentList.add(DoctorFragment.applyFragment(mDepartmentInfo, info, code));

                tempTitles[i] = info.name;
            }

            FragmentViewPagerAdapter mAdapter = new FragmentViewPagerAdapter(getSupportFragmentManager(), mFragmentList, tempTitles);
            mTabViewPager.setAdapter(mAdapter);
            slidingTabs.setViewPager(mTabViewPager);
        }

    }

    @Override
    public void initialize() {

    }
}
